package com.lipert.sk2;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

public class PublicReceiver extends Thread {

	public void run() {
		DatagramSocket socketIn = null;
		try {
			socketIn = new DatagramSocket(GUI.PUBLIC_PORT);
		} catch (SocketException e1) {
			
			e1.printStackTrace();
		}
		int i = 0;
		while (true) {
			System.out.println(i++);

			byte buforIn[] = new byte[255];
			DatagramPacket packetIn = new DatagramPacket(buforIn,
					buforIn.length);

			try {
				socketIn.receive(packetIn);
			} catch (IOException e) {
				
				e.printStackTrace();
			}
			System.out.println((packetIn.getAddress()).getHostName() + " "
					+ new String(packetIn.getData()).trim());
			GUI.publicHistoryArea.append(ServerReceiver.nickList.get(ServerReceiver.addressList.indexOf((packetIn.getAddress()).getHostAddress())) + ": "
					+ new String((packetIn.getData())).trim() + "\n");
		}
	}
}
